package com.dly.blog.controller;

import com.dly.blog.annotation.IgnoreAccess;
import com.dly.blog.annotation.OpLog;
import com.dly.blog.domain.vo.ConstantRouteVO;
import com.dly.blog.domain.vo.RouteVO;
import com.dly.blog.domain.vo.UserRouterVO;
import com.dly.blog.msg.R;
import com.dly.blog.service.MenuService;
import com.dly.blog.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/router")
@AllArgsConstructor
@Tag(name="路由相关")
@OpLog("路由相关信息")
public class RouterController extends BaseController{

    private final UserService userService;

    private final MenuService menuService;

    @GetMapping("/constant_routes")
    @Operation(summary = "获取常量路由")
    @IgnoreAccess
    public ResponseEntity<R<List<RouteVO>>> getConstantRoutes(){
        return operate(()->this.successDate(userService.getConstantRoutes()));
    }

    @GetMapping("/user_routes")
    @Operation(summary = "获取用户路由")
    @PreAuthorize("hasRole('admin')")
    public ResponseEntity<R<UserRouterVO>> getUserRoutes(){
        return operate(()->this.successDate(userService.getUserRoutes()));
    }

    @GetMapping("/getAllPages")
    public ResponseEntity<R<List<String>>> getAllPages(){
        return operate(()-> this.successDate(menuService.getAllPages()));
    }
}
